<?php

//登录日志写入数据库

namespace listen;
use app\admin\model\Admin\Log as LogModel;

class LoginLog
{
	
    public function handle($user){

        $ip = request()->ip();
        if($ip <> '127.0.0.1'){
            $ip_info = \utils\IpAddress::getIpInfo($ip);
        } else {
            $ip_info = ['city'=>'本机','isp'=>'本机地址'];
        }
        $data['ip'] = $ip;
        $data['city'] = $ip_info['city'];
        $data['isp'] = $ip_info['isp'];

        $data['application_name'] = app('http')->getName();
        $data['username'] = $user['username'];
        $data['creater_id'] = $user['user_id'];
        $data['creater_dept'] = $user['dept_id'];
		$data['url'] = request()->url(true);
		$data['useragent'] = request()->server('HTTP_USER_AGENT');
		$data['create_time'] = date('Y-m-d H:i:s');
		$data['type'] = 1;
        $data['status'] = 1;

        $loginfo = LogModel::create($data);
        if($loginfo->id){
            LogModel::update(['sort_id'=>$loginfo->id,'id'=>$loginfo->id]);
        }
    }
}